/**
 * @author 董一华
 * @since 1.00
 * @version 1.00
 * 
 * 是否集采机型下拉框控件
 * 使用说明：
 * jsp中使用范例(最短模式)：<htdz-tag:SelectFDTag />
 * 			   (最常用模式)：<htdz-tag:SelectFDTag selected="${xxx}"/>
 * 参数说明：
 * 1. name可以不写,缺省值为FDflag
 * 2. id可以不写,缺省值为name的值
 * 3. onchange可以不写，缺省值为无
 * 4. firstoption为首个下拉框的text。可以不写，缺省值为"全部机型"；
 *    如果firstoption为MyConstant.SELECT_NO_FIRST_OPTION，则表示此下拉框不需要添加额外option
 * 5. firstvalue为首个下拉框的value。可以不写，缺省值为"MyConstant.SELECT_FIRST_VALUE"  
 * 6. selected为下拉框选中的值，可以不写。
 * 
 * 修订列表： v1.00 2010-08-20 
 * 			修订人：董一华
 * 			修订内容：初始版本
 * 
 */

package com.zjht.gmcc.bean.tag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import com.zjht.gmcc.bean.util.MyConstant;

public class SelectFDTag extends TagSupport {
	private static final long serialVersionUID = 7143312033252888637L;
	private String name;
	private String id;
	private String firstoption;
	private String firstvalue;
	private String onchange;
	private String selected;

	// private boolean hidedesc;

	public SelectFDTag() {
	}

	@SuppressWarnings("static-access")
	public int doStartTag() throws JspException {
		String name = this.name;
		String id = this.id;
		String firstoption = this.firstoption;
		String firstvalue = this.firstvalue;
		String onchange = this.onchange;
		String selected = this.selected;
		// boolean hidedesc = this.hidedesc;

		if (name == null || name.length() == 0) {
			name = "FDflag";
		}

		if (id == null || id.length() == 0) {
			id = name;
		}

		StringBuilder html = new StringBuilder();
		try {
			html.append("<select name=\"");
			html.append(name);
			html.append("\"	id=\"");
			html.append(id);
			html.append("\" ");
			if (onchange != null && onchange.length() > 0) {
				html.append("onchange=\"");
				html.append(onchange);
				html.append("\"");
			}
			html.append(">");
			if (!MyConstant.SELECT_NO_FIRST_OPTION.equals(firstoption))// 如果firstoption为MyConstant.SELECT_NO_FIRST_OPTION，则不需要添加额外的option
			{
				if (firstoption == null || firstoption.length() == 0)
					firstoption = "全部机型";

				if (firstvalue == null || firstvalue.length() == 0)
					firstvalue = MyConstant.SELECT_FIRST_VALUE;

				html.append("<option value=\"");
				html.append(firstvalue);
				html.append("\">");
				html.append(firstoption);
				html.append("</option>");
			}
			html.append("<option value=\"0\" ");
			if ("0".equals(selected))
				html.append("selected");
			html.append(">非集采机型</option>");
			html.append("<option value=\"1\" ");
			if ("1".equals(selected))
				html.append("selected");
			html.append(">集采机型</option></select>");
			pageContext.getOut().print(html.toString());
		} catch (Exception e) {
			throw new JspException(e.getMessage());
		}
		html=null;
		return this.SKIP_BODY;
	}

	public void setName(String newName) {
		name = newName;
	}

	public void setId(String newId) {
		id = newId;
	}

	public void setFirstoption(String firstoption) {
		this.firstoption = firstoption;
	}

	public void setOnchange(String onchange) {
		this.onchange = onchange;
	}

	public void setSelected(String selected) {
		this.selected = selected;
	}

	public void setFirstvalue(String firstvalue) {
		this.firstvalue = firstvalue;
	}
}
